package com.troll.wanandroid.adapter.system

import android.view.View
import android.widget.ImageView
import android.widget.Toast
import com.chad.library.adapter.base.entity.node.BaseExpandNode
import com.chad.library.adapter.base.entity.node.BaseNode
import com.chad.library.adapter.base.provider.BaseNodeProvider
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.troll.eth.ex.cast
import com.troll.wanandroid.R
import com.troll.wanandroid.model.SystemKnowledge

/**
 *
 * @Author:   TangPeng
 * @Time:     6/10/21
 * @Remark:
 */
class SystemTitleProvider : BaseNodeProvider() {

    override val itemViewType: Int
        get() = SystemAdapter.SYSTEM_NODE_TITLE

    override val layoutId: Int
        get() = R.layout.layout_item_system_title

    override fun convert(helper: BaseViewHolder, item: BaseNode) {
        item.cast<SystemKnowledge> {
            helper.setText(R.id.item_system_tv_title, it.name)
        }
    }

    override fun onChildClick(helper: BaseViewHolder, view: View, data: BaseNode, position: Int) {
        when (view.id) {
            R.id.item_system_iv_arrow -> {
                data.cast<BaseExpandNode> {
                    helper.getView<ImageView>(R.id.item_system_iv_arrow).isSelected = it.isExpanded
                    getAdapter()?.expandOrCollapse(position)
                }
            }
        }
    }

    override fun onClick(helper: BaseViewHolder, view: View, data: BaseNode, position: Int) {
        getAdapter()?.expandOrCollapse(position)
        println("数据 $position")
    }
}